#!/usr/bin/env bash
# Copyright (c) 2021 The Toltec Contributors
# SPDX-License-Identifier: MIT

pkgnames=(vnsee)
pkgdesc="VNC client allowing you to use the device as a second screen"
url=https://github.com/matteodelabre/vnsee
pkgver=0.4.1-2
timestamp=2021-08-29T13:45:26Z
section="screensharing"
maintainer="Mattéo Delabre <spam@delab.re>"
license=GPL-3.0-only
installdepends=(display libvncclient nmap simple)
makedepends=(host:libvncclient host:libvncserver-dev)

image=base:v2.1
_boost_pp_ver=5e17804af2496e13ca0cc03d892b5351b637ea43
source=(
    "https://github.com/matteodelabre/vnsee/archive/v${pkgver%-*}.zip"
    "https://github.com/boostorg/preprocessor/archive/$_boost_pp_ver.zip"
    vnsee-gui-set-path.patch
    vnsee.png
    vnsee.draft
    VNSee.oxide
)
sha256sums=(
    bf6fd0d6478f0dd865bb25a4a4c061f306f53c84cff06ab51e0db36f518d6af9
    3f2f07a0c0a0d7bb1392e646a40f73028069e4fe1fa18dd7fc45ef5f66641f32
    SKIP
    SKIP
    SKIP
    SKIP
)
noextract=(
    "$_boost_pp_ver.zip"
)

prepare() {
    patch -d "$srcdir" -p1 < "$srcdir"/vnsee-gui-set-path.patch
    bsdtar --strip-components 1 \
        -xf "$srcdir"/"$_boost_pp_ver".zip \
        -C "$srcdir"/vendor/boost-preprocessor
}

build() {
    cmake -B build \
        -DCMAKE_TOOLCHAIN_FILE="/usr/share/cmake/$CHOST.cmake" \
        -DCMAKE_INSTALL_PREFIX="/opt"
    cmake --build build
}

package() {
    install -D -m 755 -t "$pkgdir"/opt/bin "$srcdir"/build/vnsee "$srcdir"/vnsee-gui
    install -D -m 644 -t "$pkgdir"/opt/etc/draft/icons "$srcdir"/vnsee.png
    install -D -m 644 -t "$pkgdir"/opt/etc/draft "$srcdir"/vnsee.draft
    install -D -m 644 -t "$pkgdir"/opt/usr/share/applications "$srcdir"/VNSee.oxide
}
